package com.wofish.web.controller.member;

import java.util.List;

import com.wofish.member.domain.MemberAdvance;
import com.wofish.member.service.IMemberAdvanceService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wofish.common.annotation.Log;
import com.wofish.common.enums.BusinessType;
import com.wofish.common.core.controller.BaseController;
import com.wofish.common.core.page.TableDataInfo;
import com.wofish.common.core.domain.AjaxResult;
import com.wofish.common.utils.poi.ExcelUtil;

/**
 * 余额明细 信息操作处理
 * 
 * @author wofish
 * @date 2019-05-21
 */
@Controller
@RequestMapping("/member/memberAdvance")
public class MemberAdvanceController extends BaseController {
    private String prefix = "member/memberAdvance";
	
	@Autowired
	private IMemberAdvanceService memberAdvanceService;
	
	@RequiresPermissions("member:memberAdvance:view")
	@GetMapping()
	public String memberAdvance() {
	    return prefix + "/memberAdvance";
	}
	
	/**
	 * 查询余额明细列表
	 */
	@RequiresPermissions("member:memberAdvance:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(MemberAdvance memberAdvance) {
		startPage();
        List<MemberAdvance> list = memberAdvanceService.selectMemberAdvanceList(memberAdvance);
		return getDataTable(list);
	}
	



	/**
	 * 导出余额明细列表
	 */
	@RequiresPermissions("member:memberAdvance:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MemberAdvance memberAdvance) {
    	List<MemberAdvance> list = memberAdvanceService.selectMemberAdvanceList(memberAdvance);
        ExcelUtil<MemberAdvance> util = new ExcelUtil<MemberAdvance>(MemberAdvance.class);
        return util.exportExcel(list, "memberAdvance");
    }
	
	/**
	 * 新增余额明细
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存余额明细
	 */
	@RequiresPermissions("member:memberAdvance:add")
	@Log(title = "余额明细", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(MemberAdvance memberAdvance) {
		return toAjax(memberAdvanceService.insertMemberAdvance(memberAdvance));
	}

	/**
	 * 修改余额明细
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		MemberAdvance memberAdvance = memberAdvanceService.selectMemberAdvanceById(id);
		mmap.put("memberAdvance", memberAdvance);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存余额明细
	 */
	@RequiresPermissions("member:memberAdvance:edit")
	@Log(title = "余额明细", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(MemberAdvance memberAdvance) {
		return toAjax(memberAdvanceService.updateMemberAdvance(memberAdvance));
	}
	
	/**
	 * 删除余额明细
	 */
	@RequiresPermissions("member:memberAdvance:remove")
	@Log(title = "余额明细", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(memberAdvanceService.deleteMemberAdvanceByIds(ids));
	}
	
}
